package com.project.entity.sys;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import com.project.dao.annotation.Like;

/**
 * 系统用户
 * @author
 */
@Entity
@Table(name="S_USER")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@DynamicInsert
@DynamicUpdate
public class User extends BaseEntity  {

	private static final long serialVersionUID = 1L;
	@Like
	@Column(name = "user_code", length = 20,unique = true ,nullable = false)
	private String userCode;		//用户帐号
	@Column(name = "password", length = 50)
    private String password;		//密码
	@Column(name = "name", length = 20)
	@Like
    private String name;			//姓名
	@Column(name = "sex", length = 1)
    private String sex;				//性别（0：女 ；1：男）
	@Column(name = "telephone", length = 20)
    private String telephone;		//座机
	@Column(name = "mobile", length = 11)
	@Like
    private String mobile;			//手机
	@Column(name = "email", length = 30)
    private String email;			//邮件
	@Column(name = "status", length = 1)
	private String status;			//是否启用（0：禁用；1：启用）
	@Column(name = "create_user", length = 20)
	private String createUser;		//创建人
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "create_time", length = 19)
    private Date createTime;		//创建时间
	@Column(name = "update_user", length = 20)
    private String updateUser;	//修改人
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "update_time", length = 19)
    private Date updateTime;		//更新时间
	@Column(name = "rmk", length = 200)
    private String rmk;				//备注
	@Column(name = "dept", length = 20)
	private String dept;
	@Column(name = "identity", length = 1)
	private String identity;//身份（1、总部，2、分公司，3、加盟商）
	@Column(name = "province", length = 6)
	private String province;//所属省
	@Column(name = "city", length = 6)
	private String city;//所属市
	@Column(name = "municipality", length = 6)
	private String municipality;//所属区
	
    
	@ManyToMany
    @JoinTable(name="S_USER_ROLE", 
    		joinColumns = { @JoinColumn(name = "USER_ID",nullable = false) }, 
    		inverseJoinColumns = { @JoinColumn(name = "ROLE_ID",nullable = false) },
    		uniqueConstraints = {@UniqueConstraint(columnNames={"USER_ID","ROLE_ID"})})
    private List<Role> roles = new ArrayList<Role>();//角色
	
	@OneToOne
	@JoinColumn(name="dept",referencedColumnName="code",insertable=false,updatable=false)
	private Department department;//所属部门
	
	public String getUserCode() {
		return userCode;
	}
	public void setUserCode(String userCode) {
		this.userCode = userCode;
	}
	
	
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	
	
	public String getTelephone() {
		return telephone;
	}
	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}
	
	
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	
	
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	
	
	public String getCreateUser() {
		return createUser;
	}
	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}
	
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	
	public String getUpdateUser() {
		return updateUser;
	}
	public void setUpdateUser(String updateUser) {
		this.updateUser = updateUser;
	}
	
	
	public Date getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	
	public String getRmk() {
		return rmk;
	}
	public void setRmk(String rmk) {
		this.rmk = rmk;
	}
	
	public List<Role> getRoles() {
		return roles;
	}
	
	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	public String getDept() {
		return dept;
	}
	public void setDept(String dept) {
		this.dept = dept;
	}
	public Department getDepartment() {
		return department;
	}
	public void setDepartment(Department department) {
		this.department = department;
	}
	public String getIdentity() {
		return identity;
	}
	public void setIdentity(String identity) {
		this.identity = identity;
	}
	public String getProvince() {
		return province;
	}
	public void setProvince(String province) {
		this.province = province;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
	public String getMunicipality() {
		return municipality;
	}
	public void setMunicipality(String municipality) {
		this.municipality = municipality;
	}
	
	
}
